# Virtual Router Simulator 
#
# Copyright (C) 2009-2010 VRSim Project
# Author: Choonho Son <choonho@kt.com>
# URL: <http://vrsim.googlecode.com>
# For license information, see LICENSE.TXT
#

from PyQt4 import QtCore, QtGui

from VRSim.Globals.Symbols import SYMBOLS
from VRSim.Node.Node import Node
from VRSim.Utils import translate

class NodesDock(QtGui.QTreeWidget):
    
    def __init__(self,  parent):
        QtGui.QTreeWidget.__init__(self,  parent)
        self.header().hide()
        
        print "nodes dock"
        
    def populateNodeDock(self):
        self.clear()
        
        print SYMBOLS
        parent_emulated_device = self
        
        count = 0
        for symbol in SYMBOLS:
            item = QtGui.QTreeWidgetItem(parent_emulated_device,  1000 + count)
            item.setText(0,  translate("NodesDock",  symbol['name']))
            #item.setText(0,  symbol['name'])
            item.setIcon(0,  QtGui.QIcon(symbol['normal_svg_file']))
            count += 1
            
    def retranslateUi(self,  MainWindow):
        self.populateNodeDock()

    ##########################
    # Mouse event
    ##########################
    def mouseMoveEvent(self,  event):
        if( (event.button() & QtCore.Qt.LeftButton) == None or self.currentItem() == None):
            return
        
        item = self.currentItem()
        if not item.type():
            return
        
        drag = QtGui.QDrag(self)
        mimedata = QtCore.QMimeData()
        
        mimedata.setText(SYMBOLS[item.type() - 1000]['name'])
        iconeSize = self.iconSize()
        icone = item.icon(0)
        drag.setMimeData(mimedata)
        drag.setHotSpot(QtCore.QPoint(iconeSize.width(),  iconeSize.height()))
        drag.setPixmap(icone.pixmap(iconeSize))
        drag.start(QtCore.Qt.MoveAction)
        

